<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2014.07.28.
   家居商家留言控制器($$)*/

!defined('Q_PATH') && exit;

class JiajucompanyguestbookController extends AController{

	public function filter_(&$arrMap){
		$arrMap['A.jiajucompanyguestbook_content']=array('like',"%".Q::G('jiajucompanyguestbook_content')."%");
		$arrMap['A.jiajucompanyguestbook_name']=array('like',"%".Q::G('jiajucompanyguestbook_name')."%");
		$arrMap['A.jiajucompanyguestbook_replycontent']=array('like',"%".Q::G('jiajucompanyguestbook_replycontent')."%");
		$arrMap['A.jiajucompanyguestbook_qq']=array('like',"%".Q::G('jiajucompanyguestbook_qq')."%");
		$arrMap['A.jiajucompanyguestbook_mobile']=array('like',"%".Q::G('jiajucompanyguestbook_mobile')."%");
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);

		// 待审
		$this->getAudit_('A.jiajucompanyguestbook_status',$arrMap);
	}

	public function index($sModel=null,$bDisplay=true){
		parent::index('jiajucompanyguestbook',false);
		$this->display(Admin_Extend::template('jiaju','jiajucompanyguestbook/index'));
	}

	protected function sqljoin_(){
		return "->join('".Q::C('DB_PREFIX')."jiajucompany AS C','C.jiajucompany_id,C.jiajucompany_fullname,C.jiajucompany_isfvip,C.jiajucompany_domain','A.jiajucompany_id=C.jiajucompany_id')";
	}

	public function reply(){
		$nGuestbookId=intval(Q::G('value'));
		if(empty($nGuestbookId)){
			exit('未指定回复的留言ID');
		}

		$arrWhere=array();
		$arrWhere['jiajucompanyguestbook_id']=$nGuestbookId;

		$oJiajucompanyguestbook=JiajucompanyguestbookModel::F()->where($arrWhere)->getOne();
		if(empty($oJiajucompanyguestbook['jiajucompanyguestbook_id'])){
			exit('待回复的留言不存在');
		}

		// 保存留言回复
		if($this->isPost()){
			$oJiajucompanyguestbook->jiajucompanyguestbook_replyusername=$GLOBALS['___login___']['user_name'];
			$oJiajucompanyguestbook->jiajucompanyguestbook_replyuserid=$GLOBALS['___login___']['user_id'];
			$oJiajucompanyguestbook->jiajucompanyguestbook_replytime=CURRENT_TIMESTAMP;
			$oJiajucompanyguestbook->save('update');
			if($oJiajucompanyguestbook->isError()){
				$this->E($oJiajucompanyguestbook->getErrorMessage());
			}else{
				$arrData=array(
					'guestbook_id'=>$oJiajucompanyguestbook['jiajucompanyguestbook_id'],
					'user_name'=>$GLOBALS['___login___']['user_name'],
					'reply_content'=>Core_Extend::ubb(Q::G('jiajucompanyguestbook_replycontent'),false),
					'reply_time'=>date('Y-m-d H:i',CURRENT_TIMESTAMP),
				);
				
				$this->A($arrData,'留言回复成功',1);
			}
		}

		$this->assign('oJiajucompanyguestbook',$oJiajucompanyguestbook);
		$this->display(Admin_Extend::template('jiaju','jiajucompanyguestbook/reply'));
	}

	public function edit($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		parent::edit('jiajucompanyguestbook',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajucompanyguestbook/add'));
	}

	public function update($sModel=null,$nId=null){
		$nId=Q::G('value');
		parent::update('jiajucompanyguestbook',$nId);
	}

	public function forbid($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::forbid('jiajucompanyguestbook',$nId,true);
	}

	public function resume($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::resume('jiajucompanyguestbook',$nId,true);
	}

	public function clear_recycle($sModel=null,$sField='status'){
		parent::clear_recycle('jiajucompanyguestbook',$sField);
	}

	public function foreverdelete_deep($sModel=null,$sId=null){
		$sId=Q::G('value');
		parent::foreverdelete_deep('jiajucompanyguestbook',$sId);
	}

	public function foreverdelete($sModel=null,$sId=null,$bApp=false){
		$sId=Q::G('value');
		parent::foreverdelete('jiajucompanyguestbook',$sId,true);
	}

	public function view_preview($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		parent::view_preview('jiajucompanyguestbook',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajucompanyguestbook/viewpreview'));
	}

	public function save_preview($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_preview('jiajucompanyguestbook',$nId);
	}

	public function save_previewstatus($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_previewstatus('jiajucompanyguestbook',$nId);
	}

}
